home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / imengv3.41p2.lha / ImEngV3.41p2 / Extra / ARexx / IndexClone.rexx < prev    next >
OS/2 REXX Batch file  |  1997-01-06  |  2KB  |  63 lines

  1. /*
  2. ** $VER: IndexClone.rexx 1.03 (4/1 Stockholm/Sweden)
  3. ** Copyright © 1997 by Patrik M Nydensten 
  4. **
  5. ** Clones files with an index number.
  6. ** The new name will be the new specified basename with the same
  7. ** index number as the original files.
  8. **
  9. ** Usage: <new_basename> <first_index_file> <last_index_file>
  10. */
  11.  
  12. options results
  13.  
  14. parse arg newbase files
  15. if pos('"',files) = 0 then parse var files file1 file2
  16. else parse var files '"'file1'"' '"'file2'"'
  17.  
  18. fix = strip(get_ext(file1)) ; lix = strip(get_ext(file2))
  19. if ((~datatype(fix,'N'))|(~datatype(lix,'N'))) then errorx('Error: Bad index number in file name.')
  20. fi = min(fix,lix) ; li = max(fix,lix)
  21.  
  22. if newbase = '' then errorx('Error: Bad new basename')
  23. do i = fi to li
  24.   new_file = get_path(file1)||newbase'.'right(i,4,'0')
  25.   old_file = get_base(file1)'.'right(i,4,'0')
  26.   if exists(old_file) then do
  27.     if ~exists(new_file) then do
  28.       address 'COMMAND' 'copy' '"'old_file'"' '"'new_file'"'
  29.     end
  30.     else say 'Error: File already exists. "'old_file'".'
  31.   end
  32.   else say 'Error: Could not locate file "'old_file'".'
  33. end
  34.  
  35. exit
  36.  
  37. /* --[ proc ]--------------------------- */
  38.  
  39. errorx:
  40.   parse arg text
  41.   say text
  42.   exit 5
  43. return 0
  44.  
  45. get_ext:
  46.   parse arg get_ext_in
  47.   if lastpos('.',get_ext_in) ~= 0 then get_ext_back = substr(get_ext_in,1+lastpos('.',get_ext_in))
  48.   else get_ext_back = ''
  49. return get_ext_back
  50.  
  51. get_base:
  52.   parse arg get_base_in
  53.   if lastpos('.',get_base_in) ~= 0 then get_base_back = substr(get_base_in,1,lastpos('.',get_base_in)-1)
  54.   else get_base_back = get_base_in
  55. return get_base_back
  56.  
  57. get_path:
  58.   parse arg get_path_in
  59.   if lastpos('/',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos('/',get_path_in))
  60.   else if lastpos(':',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos(':',get_path_in))
  61.   else get_path_back = ''
  62. return get_path_back
  63.